import {ElNotification, ElMessageBox} from "element-plus";
import nprogress from "nprogress";
//消息提示
export function notify(msg, type = "success", dangerouslyUseHTMLString = false) {
    ElNotification({
        message: msg,
        type,
        dangerouslyUseHTMLString,
        duration: 1900
    })
}
// 确认框
export function msgBox(msg = "提示内容", type = "warning", title = "提示") {
    return ElMessageBox.confirm(
        msg,
        title,
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type
        }
    )
}
//显示全屏loading
export function showFullLoading(){
    nprogress.start()
}
//隐藏全屏loading
export function hideFullLoading(){
    nprogress.done()
}



export function queryParams(data, isPrefix) {
    isPrefix = isPrefix ? isPrefix : false
    let prefix = isPrefix ? '?' : ''
    let _result = []
    for (let key in data) {
        let value = data[key]
        // 去掉为空的参数
        if (['', undefined, null].includes(value)) {
            continue
        }
        if (value.constructor === Array) {
            value.forEach(_value => {
                _result.push(encodeURIComponent(key) + '[]=' + encodeURIComponent(_value))
            })
        } else {
            _result.push(encodeURIComponent(key) + '=' + encodeURIComponent(value))
        }
    }

    return _result.length ? prefix + _result.join('&') : ''
}